-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canonicalize paths before stripping current dir as prefix #6290
Canonicalize paths before stripping current dir as prefix #6290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right fix.
Yes this does fix the very specific instance you ran into but it doesn't adress the root cause of the problem. Right now you only canonicalize the paths if they exist. (also you crash the editor if CWD doesn't exist, we do that elsewhere too but we really shouldn't do that). If clangd
had sent a message for a file that is not yet saved to disk (but exists as a buffer in helix) the same problem would occur. Furthermore there also many other places where we canonicalize paths in helix where having the normal canonicalization/normalization function being unreliable is a problem too and can lead to similar bugs.
As I described here: #6182 (comment) you need to change get_normalized_path
to canonicalize the first parent that exists (and normalize the rest with the existing code). You can then use that function to normalize cwd (and the argument) in get_relative_path
e0f2c4a
to
02ebcff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now, thanks for sticking with it! one minor nit
helix-core/src/path.rs
Outdated
.find(|path| path.exists()) | ||
.and_then(|path| Some((path, dunce::canonicalize(path).ok()?))) | ||
.map(|(base, canonicalized)| { | ||
( | ||
canonicalized, | ||
path.strip_prefix(base).unwrap(/* base is an ancestor of path */).into(), | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.find(|path| path.exists()) | |
.and_then(|path| Some((path, dunce::canonicalize(path).ok()?))) | |
.map(|(base, canonicalized)| { | |
( | |
canonicalized, | |
path.strip_prefix(base).unwrap(/* base is an ancestor of path */).into(), | |
) | |
}) | |
.find_map(|base| { | |
let canonicalized_base = dunce::canonicalize(base).ok()?; | |
Some((canonicalized_base, path.strip_prefix(base))) | |
}) |
just because a path exists doesn't mean cannonicalization necessary successed (Sadly). Using find_map
ensures we only stoip once canonicalization succedes. It's also a bit cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(didn't mean to approve yet until you accept my suggestion 😅 )
Test suite also needs to ne updated in a couple places (the previous paths assumed that we wouldn't cannonicalize)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah whoops I didn't see the conflict with #6156. Could you rebase this?
…or#6290) Co-authored-by: jazzfool <shamoslover69@gmail.com>
…or#6290) Co-authored-by: jazzfool <shamoslover69@gmail.com>
…or#6290) Co-authored-by: jazzfool <shamoslover69@gmail.com>
Fixes #6182